import React, { Component } from 'react'
import Taro from "@tarojs/taro";
import { AtCheckbox, AtIcon, AtInput } from 'taro-ui'
import { View, Text, Block, Radio,Button } from '@tarojs/components'
import './patientManagement.less'
import TabBar from "../common/taBar"
/**
 * 就诊人管理
 */
class PatientManagement extends Component {
  props: any;
  state: { value };

  constructor(props: {} | Readonly<{ any: any }>) {
    super(props)
    this.state = {
      value: ''
    }

  }
  handleChange(value: any) {
    this.setState({
      checkedList: value
    })
  }
  setState(arg0: { checkedList: any; }) {
    throw new Error('Method not implemented.');
  }
  componentDidMount() {

  }
  //改变radio
  onchangeRadio(indexNum: any) {
    Taro.showModal({
      title: '提示',
      content: `设为默认就诊人！`,
      showCancel: false,
      success: (res) => {
        if (res.confirm) {
          this.props.parent.changeDefaultPatient(indexNum);
          Taro.request({
            // url: APIBASEURL+`/patientManagerStatus`,
            url: `/patientManagerStatus`,
            data: {
              itemcode: this.props.patientItem.itemcode
              // userCode:this.state.userCode,
            },
            header: {
              'content-type': 'application/json'
            },
            method: 'PUT',
            dataType: 'json',
            credentials: 'include',
            success: (res) => {
              Taro.showToast({
                title: '默认就诊人设置成功！',
                icon: 'none',
                duration: 3000
              })
            },
            fail: function (errMsg) {
              Taro.showToast({
                title: '服务器请求错误',
                icon: 'none',
                duration: 3000
              })
            }
          });
        } else if (res.cancel) {
        }
      }
    })
  }

  //删除就诊人
  onDeletePatient(itemcode: any) {
    let code = this.props.userCode
    Taro.showModal({
      title: '提示',
      content: `确定删除？`,
      success: function (res) {
        // if (res.confirm) {
        //   Taro.request({
        //     url: APIBASEURL+`/patientManager`,
        //     data: {
        //       itemcode: itemcode,//就诊人code
        //       userCode:code,//用户code
        //     },
        //     header: {
        //       'content-type': 'application/json' // 默认值
        //     },
        //     method: 'DELETE',
        //     dataType: 'json',
        //     credentials: 'include',
        //     success: (res) => {
        //       Taro.showToast({
        //         title: '就诊人信息删除成功！',
        //         icon: 'none',
        //         duration: 3000
        //       });
        //       Taro.redirectTo({url: 'index'})
        //     },
        //     fail: function (errMsg) {
        //       Taro.showToast({
        //         title: '服务器请求错误',
        //         icon: 'none',
        //         duration: 3000
        //       })
        //     }
        //   });
        // } else if (res.cancel) {
        // }
      }
    })
  }

  //编辑就诊人
  onEditPatient(itemcode: string) {
    Taro.navigateTo({ url: `patientManagerEdit?itemcode=` + itemcode })
  }

  render() {
    // let patientItem = this.props.patientItem;

    return (

        <view>
        <view className='card-one'>
          <view className='top-info'>
            <view className='text-label'>
              <Text className='text-name'>张晓萌</Text>
              <Text>24岁</Text>
            </view>
            <view className='text-label'>
              <Text>身份证号：</Text>
              <Text>140724199608070233</Text>
            </view>
            <view className='text-label'>
              <Text>住址：</Text>
              <Text>河北省石家庄市桥西区</Text>
            </view>
          </view>


          <view className='at-row bottom-edit'>
            <view className='at-col text-label'>
              <View className='at-col'>
                <Radio className='evaluate-msg-checkbox-radio'
                  checked={this.props.checkedIndex === this.props.index}
                  onClick={this.onchangeRadio.bind(this, this.props.index)}
                >  <text>默认就诊人</text></Radio>
              
              </View>
            </view>

            <view className='at-col '>
              <view className='at-row'>
                <view className='at-col text-label'>
                  <AtIcon value='edit' size='15' color='#775637'></AtIcon>
                  <text onClick={this.onEditPatient.bind(this, 2)}>编辑</text>
                </view>
                <view className='at-col text-label'>
                  <AtIcon value='trash' size='15' color='#775637'></AtIcon>
                  <text onClick={this.onDeletePatient.bind(this, 3)}>删除</text>
                </view>
              </view>
            </view>
          </view>
        </view>
        {/* -----------11---------------- */}
        <View className='patient-manager-btn'>
            <Button className='patient-add-btn' >添加就诊人</Button>
          </View>
        <TabBar tabBarCurrent={3} />
          {/* -------------11--------------- */}
        </view>

    )

  }
}

export default PatientManagement;
